from dataclasses import dataclass
from flask import request
from injector import inject
from internal.schema import AccountSmsSchema,AccountResp,AccountSchema,PrductDescSchema
from pkg.resp import validate_error_json,success_message,success_json
from internal.exception.exception import FailException
from internal.service.acccount_service import AccountService
from flask_login import login_required,current_user
@inject
@dataclass
class AccountHandler:
    account_service: AccountService
    #发送验证码
    def send_sms(self):
        req = AccountSmsSchema()
        if not req.validate():
            return validate_error_json(req.errors)
        data = self.account_service.send_sms(phone=req.phone.data)
        resp = AccountResp()
        return resp.dumps(data)
    #登录
    def login(self):
        req = AccountSchema()
        if not req.validate():
            return validate_error_json(req.errors)
        data = self.account_service.login(phone=req.phone.data,id=req.guide_id.data, code=req.code.data)
        if data.get("code")==500:
            raise  FailException(data.get("msg"))
        return success_json(data.get("data"))


